home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************************
- *
- * PDP-8 Simulation Program- simulator user interface
- *
- * ©1992 Graham Cox. All Rights Reserved.
- *
- * Modification History:
- * 9/3/92 created from scratch.
- *
- *
- *
- *************************************************************************************/
-
- #include "PDPGlobalEqu.p"
- #include "EditGlobalEqu.p"
-
- #include "PDPSimWindow.proto.h"
-
- PDPMemHdl GetMemory(WindowPtr theWindow);
- PDPRegHdl GetCPU(WindowPtr theWindow);
- PrefsRecHdl GetPrefs(WindowPtr theWindow);
- ProcessRecHdl GetProcess(WindowPtr theWindow);
- ControlHandle GetMemScrollbar(WindowPtr theWindow);
- textEdHdl NewEditRecord(WindowPtr ownerWindow);
- textEdHdl GetWEditRecord(WindowPtr theWindow);
- char IsEditKind(WindowPtr theWindow);
-
- extern GrafPtr StatBarGrafix;
-
- GetClipRect(WindowPtr theWindow,Rect *theRect)
- {
- /* returns rectangle of scrollable content area of window */
-
- Rect r;
- textEdHdl theText;
-
- if (theWindow != NIL) {
- r = theWindow->portRect;
- r.right -= 15;
- r.bottom -= 15;
- if (IsSimulator(theWindow))
- r.left = r.right-memAreaWidth;
- else {
- if (IsEditKind(theWindow)) {
- theText = GetWEditRecord(theWindow);
- r.top += GetTabBarHeight(theText) +2; /* tab bar height */
- }
- }
- *theRect = r;
- }
- }
-
-
- SetWindowClip(WindowPtr theWindow)
- {
- /* sets clip region of window to scrollable area */
-
- Rect r;
- GrafPtr savePort;
-
- GetClipRect(theWindow,&r);
- if (theWindow != NIL) {
- GetPort(&savePort);
- SetPort(theWindow);
- ClipRect(&r);
- SetPort(savePort);
- }
- }
-
-
- SetInverseClip(WindowPtr theWindow)
- {
- /* sets clip region to interior minus scrollable area and scrollbars */
- Rect r;
- GrafPtr savePort;
-
- r = theWindow->portRect;
- r.bottom -= 15;
- if (IsSimulator(theWindow))
- r.right -= memAreaWidth;
-
- GetPort(&savePort);
- SetPort(theWindow);
- ClipRect(&r);
- SetPort(savePort);
- }
-
-
- UnClipWindow(WindowPtr theWindow)
- {
- /* sets clip region to full port rect */
-
- GrafPtr savePort;
- Rect r;
-
- if (theWindow != NIL) {
- SetRect(&r,-32768,-32768,32767,32767);
- GetPort(&savePort);
- SetPort(theWindow);
- ClipRect(&r);
- SetPort(savePort);
- }
- }
-
-
- MoveScrollbar(WindowPtr theWindow,ControlHandle vS)
- {
- /* code stub shared by ResizeWindow and ZoomScrollWindow to move the scrollbar to
- the window edge. The window should have been set to the new size & bars hidden
- before calling, and theWindow must be current port */
-
- Rect tempRect;
-
- if (theWindow!=NIL && vS!=NIL){
- tempRect=(**vS).contrlRect;
- tempRect.bottom+=15; /* erase the grow icon */
- EraseRect(&tempRect);
- InvalRect(&tempRect);
-
- tempRect=theWindow->portRect;
- /* move the bar to the window edge, resizing if necessary */
-
- MoveControl(vS,tempRect.right-15,tempRect.top-1);
- SizeControl(vS,16,tempRect.bottom-tempRect.top-13);
-
- tempRect=(**vS).contrlRect;
- ValidRect(&tempRect);
- ShowControl(vS);
-
- if (IsSimulator(theWindow)) {
- ResetPCMarker(theWindow);
- tempRect=theWindow->portRect;
- tempRect.top = tempRect.bottom-14;
- tempRect.right = tempRect.left +90;
- InvalRect(&tempRect);
- }
- }
- }
-
-
- ResizeWindow(WindowPtr theWindow,int width,int height)
- {
- /* call in response to a grow or zoom request for the window- This routine moves the
- scrollbars referenced by vS (vertical) and hS (horizontal), sorts out the various
- update region manipulations required, and sets the clip region for the window to
- exclude the scrollbars. It draws the controls as required, but removes them from
- the update region to stop them being drawn twice. */
-
- Rect tempRect;
- GrafPtr savePort;
- ControlHandle vS,hS;
- int vCheck;
-
- if (theWindow!=NIL) {
- GetPort(&savePort);
- SetPort(theWindow);
-
- if (IsSimulator(theWindow)) {
- vS = GetMemScrollbar(theWindow);
-
- vCheck = GetCtlValue(vS);
-
- /* first, hide the bars and mark their areas for update */
-
- if (vS!=NIL)
- HideControl(vS);
-
- GetClipRect(theWindow,&tempRect);
- EraseRect(&tempRect);
- InvalRect(&tempRect);
- tempRect = theWindow->portRect;
- tempRect.top = tempRect.bottom-17;
- EraseRect(&tempRect);
- InvalRect(&tempRect);
-
- SizeWindow(theWindow,width,height,TRUE);
-
- GetClipRect(theWindow,&tempRect);
- EraseRect(&tempRect);
- InvalRect(&tempRect);
-
- MoveScrollbar(theWindow,vS);
- DrawGrowIcon(theWindow);
- }
- SetPort(savePort);
- }
- }
-
-
- ZoomScrollWindow(WindowPtr theWindow,int partCode,short front)
- {
- /* replaces ZoomWindow function when window has scrollbars */
-
- ControlHandle vS;
-
- if (theWindow!=NIL && IsSimulator(theWindow)) {
- vS = GetMemScrollbar(theWindow);
- if (vS!=NIL)
- HideControl(vS);
-
- ZoomWindow(theWindow,partCode,front);
- MoveScrollbar(theWindow,vS);
- DrawGrowIcon(theWindow);
- }
- }
-
-
- DrawPDPWindow(WindowPtr theWindow)
- {
- /* call to update the window, which must be of type simulator. Can be called from
- update event or whenever processor status changes. The window must be current
- port and visRgn should be set up */
-
- PicHandle diagram;
- Rect pBox;
- ControlHandle mScroll;
- ProcessRecHdl wProcess;
- PDPMemHdl procMem;
- int mHeight;
- PDPRegHdl theCPU;
- PrefsRecHdl thePrefs;
- Str32 nfString;
-
- if (IsSimulator(theWindow)) {
- wProcess = GetProcess(theWindow);
- mScroll = GetMemScrollbar(theWindow);
- procMem = GetMemory(theWindow);
- theCPU = GetCPU(theWindow);
-
- diagram = GetPicture(129);
- SetInverseClip(theWindow);
- if (diagram != NIL) {
- pBox = (*diagram)->picFrame;
- AlignToZero(&pBox);
- OffsetRect(&pBox,10,2+statusBarHeight);
- DrawPicture(diagram,&pBox);
- ReleaseResource(diagram);
- }
- DrawStatusBar(theWindow,theCPU);
- pBox = theWindow->portRect;
- MoveTo(0,statusBarHeight);
- LineTo(pBox.right,statusBarHeight);
- SetWindowClip(theWindow);
- mHeight = (*wProcess)->memLocHeight;
-
- thePrefs = GetPrefs(theWindow);
- DrawMemoryArea(GetCtlValue(mScroll),
- (*thePrefs)->NumberFormat,
- MemLocsInWindow(theWindow),
- procMem,
- mHeight,
- theCPU);
-
- SetInverseClip(theWindow);
- UpdateRegisters(theWindow);
- UnClipWindow(theWindow);
- pBox.top = pBox.bottom-12;
- pBox.right = pBox.left + 90;
- OffsetRect(&pBox,5,-2);
- GetIndString(&nfString,128,(*thePrefs)->NumberFormat+3);
- TextFont(geneva);
- TextSize(9);
- TextBox(&nfString[1],nfString[0],&pBox,teJustLeft);
- TextFont(0);
- TextSize(12);
- }
- }
-
-
- DrawMemoryArea(PDPWord topAddress,
- int NumFormat,
- int nCells,
- PDPMemHdl procMem,
- int mHeight,
- PDPRegHdl theCPU)
- {
- /* draws the memory area in the current window. Clipping and port must be set up */
-
- PDPMemPtr addrPtr;
- PDPWord data,i;
- Str32 vText;
- Rect tBox;
- int dH;
-
- if (procMem != NIL) {
- MoveTo(thePort->portRect.right-memAreaWidth,thePort->portRect.top);
- LineTo(thePort->portRect.right-memAreaWidth,thePort->portRect.bottom-15);
- dH = memAreaWidth/2-14;
- SetRect(&tBox,0,0,dH,mHeight);
- OffsetRect(&tBox,thePort->portRect.right-(memAreaWidth-14),0);
-
- HLock((Handle) procMem);
-
- for(i=topAddress;i < topAddress + nCells;i++) {
- addrPtr = *procMem;
- if (i<4096) {
- data = *(addrPtr + i);
- GetNumberString((long)i,NumFormat,&vText);
- TextBox(&vText[1],vText[0],&tBox,teJustLeft);
- InsetRect(&tBox,-1,-1);
- FrameRect(&tBox);
- InsetRect(&tBox,1,1);
- OffsetRect(&tBox,dH,0);
- GetNumberString((long)data,NumFormat,&vText);
- TextBox(&vText[1],vText[0],&tBox,teJustLeft);
- InsetRect(&tBox,-1,-1);
- FrameRect(&tBox);
- InsetRect(&tBox,1,1);
- OffsetRect(&tBox,-dH,mHeight);
- }
- }
- HUnlock((Handle) procMem);
- PlotPCMarker(theCPU,mHeight,topAddress);
- }
- }
-
-
- RefreshSimWindow(WindowPtr theWindow)
- {
- /* draws the given sim window */
-
- GrafPtr savePort;
- ProcessRecHdl theProcess;
-
- GetPort(&savePort);
- SetPort(theWindow);
- SetWindowClip(theWindow);
- theProcess = GetProcess(theWindow);
- if (theProcess != NIL)
- PlotPCMarker(GetCPU(theWindow),
- (*theProcess)->memLocHeight,
- GetCtlValue((*theProcess)->memScroll));
-
- SetInverseClip(theWindow);
- UpdateRegisters(theWindow);
- UnClipWindow(theWindow);
- SetPort(savePort);
- }
-
-
- UpdateRegisters(WindowPtr theWindow)
- {
- /* redraws the register values in the current process window */
-
- Rect tBox;
- PDPRegHdl theCPU;
- Str32 vText;
- int numBase;
- PrefsRecHdl thePrefs;
-
- SetRect(&tBox,0,0,80,18);
- OffsetRect(&tBox,240,22+statusBarHeight);
-
- theCPU = GetCPU(theWindow);
- thePrefs = GetPrefs(theWindow);
- numBase = (*thePrefs)->NumberFormat;
- if (theCPU != NIL) {
- GetNumberString((long)(*theCPU)->PC,numBase,&vText);
- TextBox(&vText[1],vText[0],&tBox,teJustRight);
-
- OffsetRect(&tBox,0,51);
- GetNumberString((long)(*theCPU)->EAR,numBase,&vText);
- TextBox(&vText[1],vText[0],&tBox,teJustRight);
-
- OffsetRect(&tBox,0,51);
- GetNumberString((long)(*theCPU)->IR,numBase,&vText);
- TextBox(&vText[1],vText[0],&tBox,teJustRight);
-
- AlignToZero(&tBox);
- OffsetRect(&tBox,47,124+statusBarHeight);
- GetNumberString((long)(*theCPU)->ACC,numBase,&vText);
- TextBox(&vText[1],vText[0],&tBox,teJustRight);
-
- OffsetRect(&tBox,99,0);
- InsetRect(&tBox,32,0);
- GetNumberString((long)((*theCPU)->CCR & Link),numBase,&vText);
- TextBox(&vText[1],vText[0],&tBox,teJustCenter);
-
- }
- }
-
-
- GetNumberString(long theNumber,int numBase,Str32 *theString)
- {
- /* returns the string representing the number in decimal, octal or hex */
-
- if (numBase == Decimal)
- NumToString(theNumber,theString);
- else
- if (numBase == Octal)
- NumToOctal(theNumber,theString);
- else
- NumToHexx(theNumber,theString);
- }
-
-
- DrawStatusBar(WindowPtr theWindow,PDPRegHdl theCPU)
- {
- /* draws the status bar in the window. This is a copyBits from an offscreen port,
- which is done to allow the buttons to be drawn in various states easily. The
- window MUST be the current port, and clipping set up already */
-
- Rect src,dest;
- int CPUStatus;
-
- if (theWindow != NIL && theCPU != NIL) {
- CPUStatus = (*theCPU)->CCR;
- SetRect(&src,0,0,StatBarGrafix->portRect.right,statusBarHeight);
- dest = src;
- CopyBits(&StatBarGrafix->portBits,&theWindow->portBits,&src,&dest,srcCopy,NIL);
- SetRect(&src,0,0,70,20);
- dest = src;
- OffsetRect(&src,10,30);
- OffsetRect(&dest,10,0);
- if (CPUStatus & HaltBit) {
- OffsetRect(&src,80,0);
- OffsetRect(&dest,80,0);
- }
- CopyBits(&StatBarGrafix->portBits,&theWindow->portBits,&src,&dest,srcCopy,NIL);
- }
- }
-
-
- GrafPtr MakeAPort(int pictID,int pixDepth)
- {
- /* given a PICT resource ID, this routine creates an offscreen port of the depth
- specified, draws the picture into it, and returns it's pointer. The depth can be
- 8 bits or 1 bit, or if 0 is passed, the depth of the main screen is used. */
-
- OSErr theErr;
- PicHandle thePicture;
- GrafPtr thePicPort,savePort;
- Rect picRect;
- int width,height;
- long storage,rowB;
- PixMapHandle colourPix;
- Handle RAMChunk;
- GDHandle maxDev,saveDev;
-
- thePicture=GetPicture(pictID); /* fetch the picture to draw */
- if (thePicture!=NIL && (pixDepth==1 || pixDepth==8 || pixDepth==0)) {
-
- if (!IsInColour())
- pixDepth=1; /* force 1 bit graphics on B & W mac */
- else {
- if (pixDepth==0) {
- maxDev=GetMainDevice();
- if (maxDev!=NIL) {
- colourPix=(**maxDev).gdPMap;
- pixDepth=(**colourPix).pixelSize; /* determine depth of screen */
- }
- }
- }
- picRect=(**thePicture).picFrame; /* get size of picture */
- OffsetRect(&picRect,-picRect.left,-picRect.top); /* align to zero */
- thePicPort=(GrafPtr)NewPtr(sizeof(GrafPort)); /* get new port */
- if (thePicPort!=NIL) {
- GetPort(&savePort);
-
- if (pixDepth==1)
- OpenPort(thePicPort); /* initialise port as B & W */
- else
- OpenCPort(thePicPort); /* initialise port as Colour */
-
- width=picRect.right-picRect.left;
- height=picRect.bottom-picRect.top;
- thePicPort->portRect=picRect;
- RectRgn(thePicPort->visRgn,&picRect); /* set port regions to equal portrect */
- RectRgn(thePicPort->clipRgn,&picRect);
- rowB=((width * pixDepth)+15)/16 * 2; /* determine row offset */
- storage=(long)height * rowB; /* determine size of bit image for port */
- RAMChunk=NewHandle(storage); /* get a lump of memory to hold image */
- if (RAMChunk!=NIL) {
- MoveHHi(RAMChunk); /* move it out of the way */
- HLock(RAMChunk); /* lock it (accessed via pointer) */
- if (pixDepth==1) {
- /* set up bitmap for B & W port */
-
- thePicPort->portBits.bounds=picRect;
- thePicPort->portBits.rowBytes=BitAnd(rowB,0xFFFF);
- thePicPort->portBits.baseAddr=*RAMChunk;
- }
- else {
- /* set up pixmap for colour port */
-
- colourPix=(*(CGrafPtr)thePicPort).portPixMap;
- if (colourPix!=NIL) {
- (**colourPix).bounds=picRect;
- (**colourPix).rowBytes=BitOr(rowB,0x8000);
- (**colourPix).baseAddr=*RAMChunk;
- (**colourPix).pixelSize=pixDepth;
- }
- }
- SetPort(thePicPort); /* set current port to our new one */
- ForeColor(blackColor);
- BackColor(whiteColor);
- EraseRect(&thePicPort->portRect); /* clear port */
- thePicture=GetPicture(pictID); /* get picture again (it maybe got purged)*/
- DrawPicture(thePicture,&picRect); /* draw picture into offscreen image */
- ReleaseResource(thePicture); /* let picture go */
- SetPort(savePort);
- return(thePicPort);
- }
- else {
- if (pixDepth==1)
- ClosePort(thePicPort);
- else
- CloseCPort(thePicPort);
- DisposPtr(thePicPort);
- }
- }
- }
- SysBeep(1);
- return(NIL);
- }
-
-
- CloseAPort(GrafPtr theOSPort)
- {
- /* disposes of off-screen port */
-
- Handle theImage;
- PixMapHandle colourPix;
- char portIsColour;
-
- if (theOSPort!=NIL){
- portIsColour=((theOSPort->portBits.rowBytes & 0xC000)!=0); /* find out if port is colour */
- if (portIsColour) {
- colourPix=(*(CGrafPtr)theOSPort).portPixMap;
- theImage=RecoverHandle((**colourPix).baseAddr); /* find long-lost handle */
- }
- else
- theImage=RecoverHandle(theOSPort->portBits.baseAddr);
-
- if (theImage!=NIL) {
- HUnlock(theImage); /* free that locked block! */
- DisposHandle(theImage); /* dispose of image in memory */
- }
- if (portIsColour)
- CloseCPort(theOSPort);
- else
- ClosePort(theOSPort); /* dispose of port's storage */
-
- DisposPtr(theOSPort); /* get rid of the port itself */
- }
- }
-
-
- int IsInColour(void)
- {
- /* returns TRUE if a colour Mac with a colour main monitor, else FALSE */
-
- SysEnvRec macEnv;
- GDHandle macGDevice;
- OSErr theErr;
- PixMapHandle macScreen;
-
- theErr = SysEnvirons(2,&macEnv);
- if (!theErr) {
- if (macEnv.hasColorQD) {
- macGDevice = GetMainDevice();
- if (macGDevice != NIL) {
- macScreen = (*macGDevice)->gdPMap;
- if (macScreen != NIL) {
- if ((*macScreen)->pixelSize > 2)
- return(TRUE);
- }
- }
- }
- }
- return(FALSE);
- }
-
-
- int MemLocsInWindow(WindowPtr theWindow)
- {
- /* returns the number of memory locations that can be displayed in the window. This
- is just the memLocHeight divided into the window height. */
-
- ProcessRecHdl theProcess;
- Rect wRect;
-
- if (IsSimulator(theWindow)) {
- theProcess = GetProcess(theWindow);
- GetClipRect(theWindow,&wRect);
- return((wRect.bottom-wRect.top)/(*theProcess)->memLocHeight +1);
- }
- }
-
-
- PlotPCMarker(PDPRegHdl theCPU,int mLocHeight,PDPWord topAddress)
- {
- /* draws the PC marker arrow pointing to the current address. topAddress is the
- address of the location at the top of the window, and mLocHeight is the height
- in pixels of each location box. Current port must be set up with any clipping */
-
- Rect src,dest;
- PDPWord cAddr,bottomAddr;
-
- if (theCPU != NIL) {
- EraseRect(&(*theCPU)->markerLoc);
- cAddr = (*theCPU)->PC;
- if (cAddr >= topAddress && cAddr <= (topAddress + MemLocsInWindow(thePort))) {
- SetRect(&src,0,0,10,10);
- dest = src;
- OffsetRect(&src,370,38);
- OffsetRect(&dest,
- thePort->portRect.right-(memAreaWidth-2),
- (cAddr - topAddress) * mLocHeight + 5);
-
- CopyBits(&StatBarGrafix->portBits,&thePort->portBits,&src,&dest,srcCopy,NIL);
- (*theCPU)->markerLoc = dest;
- }
- }
- }
-
-
- ResetPCMarker(WindowPtr theWindow)
- {
- /* for a sim window, sets the marker rectangle to empty- required when a window is resized */
-
- PDPRegHdl theCPU;
-
- theCPU = GetCPU(theWindow);
- if (theCPU != NIL)
- SetRect(&(*theCPU)->markerLoc,0,0,0,0);
- }
-
-
- pascal void MemScrollProc(ControlHandle theControl,int partCode)
- {
- /* action procedure to scroll the memory display in the window */
-
- Rect mArea;
- RgnHandle updateRgn;
- WindowPtr target;
- ProcessRecHdl theProcess;
- PrefsRecHdl thePrefs;
- int pScrollDist,pageAmt,ctlChange;
-
- target = (*theControl)->contrlOwner;
- GetClipRect(target,&mArea);
- mArea.left +=15;
- theProcess = GetProcess(target);
- if (theProcess != NIL) {
- pageAmt = MemLocsInWindow(target)-2;
- ctlChange = GetCtlValue(theControl);
-
- switch (partCode) {
- case inUpButton:
- SetCtlValue(theControl,GetCtlValue(theControl)-1);
- break;
- case inDownButton:
- SetCtlValue(theControl,GetCtlValue(theControl)+1);
- break;
- case inPageUp:
- SetCtlValue(theControl,GetCtlValue(theControl)-pageAmt);
- break;
- case inPageDown:
- SetCtlValue(theControl,GetCtlValue(theControl)+pageAmt);
- break;
- }
-
- ctlChange = ctlChange - GetCtlValue(theControl);
- pScrollDist = (*theProcess)->memLocHeight * ctlChange;
-
- updateRgn = NewRgn();
-
- ScrollRect(&mArea,0,pScrollDist,updateRgn);
- InvalRgn(updateRgn);
- BeginUpdate(target);
- thePrefs = GetPrefs(target);
- DrawMemoryArea(GetCtlValue(theControl),
- (*thePrefs)->NumberFormat,
- pageAmt+2,
- GetMemory(target),
- (*theProcess)->memLocHeight,
- GetCPU(target));
-
- EndUpdate(target);
- DisposeRgn(updateRgn);
- }
- }
-
-
- ClickSimWindow(WindowPtr theWindow,Point clickPt)
- {
- /* handles clicks for a sim window. Window is current port, and already verified
- as a sim window. ClickPt is in local coordinates */
-
- ControlHandle mBar;
- int partCode;
- Rect mRect,pRect;
- PrefsRecHdl thePrefs;
-
- partCode = FindControl(clickPt,theWindow,&mBar);
- if (partCode == inThumb) {
- partCode = TrackControl(mBar,clickPt,NIL);
- if (partCode != 0) {
- GetClipRect(theWindow,&mRect);
- if (GetCtlValue(mBar) > 4096-MemLocsInWindow(theWindow))
- EraseRect(&mRect);
- InvalRect(&mRect);
- }
- }
- else {
- if (partCode != 0)
- partCode = TrackControl(mBar,clickPt,&MemScrollProc);
- else {
- /* we did not click a control, so hit test other parts of the window */
- pRect = theWindow->portRect;
- SetRect(&mRect,0,0,pRect.right-memAreaWidth,statusBarHeight);
- if (PtInRect(clickPt,&mRect))
- StatBarHit(theWindow,clickPt);
- else {
- GetClipRect(theWindow,&mRect);
- mRect.left += memAreaWidth/2 +14;
- if (PtInRect(clickPt,&mRect)) {
- thePrefs = GetPrefs(theWindow);
- EditMemLocation(theWindow,clickPt,(*thePrefs)->NumberFormat);
- }
- else {
- GetClipRect(theWindow,&mRect);
- mRect.left+= 14;
- mRect.right = mRect.left + 14;
- if (PtInRect(clickPt,&mRect))
- SetPCToClick(GetCPU(theWindow),GetProcess(theWindow),clickPt);
- }
- }
- }
- }
- }
-
-
- StatBarHit(WindowPtr theWindow,Point clickPt)
- {
- /* hit tests buttons in the stat bar, tracking and performing action accordingly */
-
- Rect buttonRect,src,dest;
- int index;
- long dTime;
-
- SetRect(&buttonRect,0,0,70,20);
- OffsetRect(&buttonRect,10,0);
- for (index =0;index<4;index++) {
- if (PtInRect(clickPt,&buttonRect))
- break;
- OffsetRect(&buttonRect,85,0);
- }
- if (index >=4)
- return(0);
-
- SetInverseClip(theWindow);
-
- src = buttonRect;
- OffsetRect(&src,0,30);
- CopyBits(&StatBarGrafix->portBits,&theWindow->portBits,&src,&buttonRect,srcCopy,NIL);
- OffsetRect(&src,0,-30);
-
- switch (index) {
- case 0:
- ResumePDP(theWindow);
- break;
- case 1:
- StopPDP(theWindow);
- break;
- case 2:
- Delay(10,&dTime);
- ResetPDP(theWindow);
- SetInverseClip(theWindow);
- CopyBits(&StatBarGrafix->portBits,&theWindow->portBits,&src,&buttonRect,srcCopy,NIL);
- break;
- case 3:
- Delay(10,&dTime);
- StepPDP(theWindow);
- SetInverseClip(theWindow);
- CopyBits(&StatBarGrafix->portBits,&theWindow->portBits,&src,&buttonRect,srcCopy,NIL);
- break;
- }
- UnClipWindow(theWindow);
- }
-
-
- UpdateMemoryLocation(WindowPtr theWindow)
- {
- /* called when the process requests a memory update. If the affected location is
- visible in the window, that location is identified, clipped to, and the memory
- draw procedure is called. The cpu's EAR points to the location */
-
- GrafPtr savePort;
- PDPRegHdl theCPU;
- PDPWord topAddress,refreshAddr;
- PDPMemPtr targLocation;
- PrefsRecHdl thePrefs;
- Rect locRect;
- ProcessRecHdl theProcess;
- long dTime;
-
- if (IsSimulator(theWindow)) {
- topAddress = GetCtlValue(GetMemScrollbar(theWindow));
- theCPU = GetCPU(theWindow);
- refreshAddr = (*theCPU)->EAR;
- if (refreshAddr >= topAddress &&
- refreshAddr <= topAddress + MemLocsInWindow(theWindow)) {
- thePrefs = GetPrefs(theWindow);
- theProcess = GetProcess(theWindow);
- GetPort(&savePort);
- SetPort(theWindow);
-
- SetRect(&locRect,0,0,memAreaWidth/2-15,(*theProcess)->memLocHeight-3);
- OffsetRect(&locRect,theWindow->portRect.right-memAreaWidth/2,
- (refreshAddr - topAddress) * (*theProcess)->memLocHeight);
- InsetRect(&locRect,2,1);
- ClipRect(&locRect);
- DrawMemoryArea(topAddress,
- (*thePrefs)->NumberFormat,
- MemLocsInWindow(theWindow),
- GetMemory(theWindow),
- (*theProcess)->memLocHeight,
- theCPU);
- UnClipWindow(theWindow);
- SetPort(savePort);
- }
- }
- }
-
- #define EditMemLocDialogID 514
-
-
- EditMemLocation(WindowPtr theWindow,Point clickPt,int nFormat)
- {
- /* selects a memory cell for editing. Window must be current port & verified correct
- type */
-
- PDPWord topAddress,editAddress;
- ProcessRecHdl theProcess;
- Rect locRect,itemBox;
- long dTime,editData;
- DialogPtr theDialog;
- int theItem,itemType;
- Handle itemHand;
- PDPMemHdl theMemory;
- Point dialogOffset;
- Str32 aText;
-
- topAddress = GetCtlValue(GetMemScrollbar(theWindow));
- theProcess = GetProcess(theWindow);
- editAddress = topAddress + (clickPt.v / (*theProcess)->memLocHeight);
-
- if (editAddress >=0 && editAddress <4096) {
- SetRect(&locRect,0,0,memAreaWidth/2-15,(*theProcess)->memLocHeight-1);
- OffsetRect(&locRect,theWindow->portRect.right- memAreaWidth/2,
- (editAddress - topAddress) * (*theProcess)->memLocHeight);
-
- SetWindowClip(theWindow);
- InvertRect(&locRect);
- Delay(8,&dTime);
- InvertRect(&locRect);
- UnClipWindow(theWindow);
-
- dialogOffset.h = locRect.left -46;
- dialogOffset.v = locRect.top -3;
- LocalToGlobal(&dialogOffset);
-
- theMemory = GetMemory(theWindow);
- editData = *(*theMemory + editAddress);
- switch(nFormat) {
- case Decimal:
- NumToString(editData,&aText);
- break;
- case Octal:
- NumToOctal(editData,&aText);
- break;
- case Hexadecimal:
- NumToHexx(editData,&aText);
- break;
- }
-
-
- theDialog = GetNewDialog(EditMemLocDialogID,NIL,(WindowPtr)-1L);
- if (theDialog != NIL) {
- MoveWindow(theDialog,dialogOffset.h,dialogOffset.v,TRUE);
- ShowWindow(theDialog);
- GetDItem(theDialog,2,&itemType,&itemHand,&itemBox);
- SetIText(itemHand,&aText);
- SelIText(theDialog,2,0,32767);
-
- ModalDialog(NIL,&theItem);
-
- GetIText(itemHand,&aText);
- DisposDialog(theDialog);
-
- switch (nFormat) {
- case Decimal:
- StringToNum(&aText,&editData);
- break;
- case Octal:
- OctStringToNum(&aText,&editData);
- break;
- case Hexadecimal:
- HexStringToNum(&aText,&editData);
- break;
- }
- *(*theMemory + editAddress) = (LoWord(editData) & 0x0FFF);
- }
- }
- else
- SysBeep(1);
- }
-
-
- SetPCToClick(PDPRegHdl theCPU,ProcessRecHdl theProcess,Point mClick)
- {
- /* when mouse clicked in marker bar, address of click calculated and copied to the
- program counter, then the marker is replotted. thePort must be current window */
-
- PDPWord topAddress,ckAddress;
- Rect pcRect;
-
- if ((*theCPU)->CCR & HaltBit) {
- topAddress = GetCtlValue((*theProcess)->memScroll);
- ckAddress = topAddress + mClick.v / (*theProcess)->memLocHeight;
- if (ckAddress >=0 && ckAddress <4096) {
- (*theCPU)->PC = ckAddress;
- SetWindowClip(thePort);
- PlotPCMarker(theCPU,(*theProcess)->memLocHeight,topAddress);
- SetRect(&pcRect,0,0,80,18);
- OffsetRect(&pcRect,240,22+statusBarHeight);
- InvalRect(&pcRect);
- UnClipWindow(thePort);
- }
- else
- SysBeep(1);
- }
- else
- SysBeep(1);
- }
-
-
- ScrollToPC(WindowPtr theWindow)
- {
- /* changes memory view so that current PC is first location shown */
-
- Rect mView;
- GrafPtr savePort;
- ControlHandle mScroll;
- PDPRegHdl theCPU;
-
- if (IsSimulator(theWindow)) {
- GetClipRect(theWindow,&mView);
- mScroll = GetMemScrollbar(theWindow);
- theCPU = GetCPU(theWindow);
- if (mScroll != NIL && theCPU != NIL)
- SetCtlValue(mScroll,(*theCPU)->PC);
-
- GetPort(&savePort);
- SetPort(theWindow);
- InvalRect(&mView);
- SetPort(savePort);
- }
- }